package mianyang.zhangsan.com.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import mianyang.zhangsan.com.pojo.Admin;
import mianyang.zhangsan.com.pojo.Student;
import mianyang.zhangsan.com.pojo.Teacher;
import mianyang.zhangsan.com.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/student")
public class StudentController {
    @Autowired
    private StudentService studentService;

    /**
     * 查询学生信息
     * @param page
     * @param rows
     * @param clazzId
     * @param session
     * @return
     */
    @RequestMapping("/list")
    @ResponseBody
    public Object list(@RequestParam(value = "page", defaultValue = "1" )int page,
                       @RequestParam(value = "rows", defaultValue = "10") int rows,
                       @RequestParam(value = "clazzId", defaultValue = "0")int clazzId,
                       HttpSession session){
        Map<String, Object> result = new HashMap<>();
        String usertype = (String)session.getAttribute("usertype");
        if ("1".equals(usertype)){
            Student student = (Student) session.getAttribute("user");
            System.out.println(student);
            result.put("rows", student);
        }else{
            Page<Student> studentPage = studentService.queryStudentByPage(page, rows, clazzId);
            result.put("total", studentPage.getPages());
            result.put("rows", studentPage.getRecords());
        }

        return result;
    }
    @RequestMapping("/comboboxList")
    @ResponseBody
    public Object comboboxList(){
        List<Student> studentList = studentService.queryInfoAll();
        return studentList;
    }
}
